const { patchRequire } = require("../utils")

const handlers = patchRequire("request")

const request = (base = {}, data = {}, opts = {}) => {
  let config = {}
  let method = base.method.toLocaleLowerCase()
  let url = base.url || ""
  data.__path &&
    (url = url + "/" + data.__path) &&
    Reflect.deleteProperty(data, "__path")
  config.url = url
  config[method === "get" ? "params" : "data"] = data
  config = { ...config, ...opts, method }
  return handlers[base.handler](config)
}

module.exports = request
